package com.example.springbatch_step_condition2;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
import org.springframework.stereotype.Component;

import java.util.Random;


/**
 * 自定义决策器
 */
@Component
public class MyStatusDecider implements JobExecutionDecider {
    public static final String A = "A";
    public static final String B = "B";
    public static final String C = "C";



    @Override
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        int randomNum = new Random().nextInt(3);
        if (randomNum == 0) {
            return new FlowExecutionStatus(A);
        } else if (randomNum == 1) {
            return new FlowExecutionStatus(B);
        } else {
            return new FlowExecutionStatus(C);
        }
    }
}











